package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

@LocalTCC
public interface AccountTCCService {

    //@TwoPhaseBusinessAction所在方法就是try方法,name与修饰方法名一致
    @TwoPhaseBusinessAction(name = "deduct", commitMethod = "confirm", rollbackMethod = "cancel")
    /**
     * 原来AccountService中的逻辑:
     * 从用户账户中扣款
     */
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId, @BusinessActionContextParameter(paramName = "money") int money);

    //@TwoPhaseBusinessAction中commitMethod指定的是confirm方法
    boolean confirm(BusinessActionContext businessActionContext);

    //@TwoPhaseBusinessAction中rollbackMethod指定的是cancel方法
    boolean cancel(BusinessActionContext businessActionContext);

}
